<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="仓库" prop="fkStockUuid">
        <el-input
          v-model="queryParams.fkStockUuid"
          placeholder="请输入仓库id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="仓库状态" prop="sysNormalDisable">
        <el-input
          v-model="queryParams.sysNormalDisable"
          placeholder="请输入状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="单据编号" prop="docNum">
        <el-input
          v-model="queryParams.docNum"
          placeholder="请输入单据编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据日期" prop="docDt">
        <el-date-picker clearable size="small"
          v-model="queryParams.docDt"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择单据时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wms:inventorySheet:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wms:inventorySheet:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wms:inventorySheet:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wms:inventorySheet:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="inventorySheetList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="单据时间" align="center" prop="docDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.docDt, '{y}-{m}-{d} {h}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单据编号" align="center" prop="docNum" width="180"/>
      <el-table-column label="仓库" align="center" prop="stockName" />
      <el-table-column label="仓库状态" align="center" prop="stockCondition">
        <template slot-scope="scope">
          <el-tag type="primary" v-if="scope.row.stockCondition=='0'">正常</el-tag>
          <el-tag type="danger"  v-if="scope.row.stockCondition=='1'">停用</el-tag>
          <el-tag type="warning" v-if="scope.row.stockCondition=='盘点中'">盘点中</el-tag>
          <el-tag type="info"    v-if="scope.row.stockCondition=='结帐中'">结帐中</el-tag>
          <el-tag type="success" v-if="scope.row.stockCondition=='初始化'">初始化</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="经办人" align="center" prop="nickName" />
      <el-table-column label="是否同意盘点" align="center" prop="oaDictConfirmStatusSubmit" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.wms_yes_no_sheet" :value="scope.row.oaDictConfirmStatusSubmit"/>
        </template>
      </el-table-column>

      <el-table-column label="审核状态" align="center" prop="oaDictConfirmStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.oa_dict_confirm_status" :value="scope.row.oaDictConfirmStatus"/>
        </template>
      </el-table-column>



      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="240" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wms:inventorySheet:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wms:inventorySheet:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-circle-check"
            @click="handleConfirm(scope.row)"
            v-hasPermi="['oa:confirm:edit']"
            :disabled="scope.row.oaDictConfirmStatusSubmit !='waiting'"
            >盘点审核
          </el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-success"
            @click="showDialog_confirm(scope.row)"
            v-hasPermi="['mes:process:remove']"
            > 审核
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改盘点管理对话框 -->
    <el-dialog v-dialogDrag v-dialogDragWidth :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-alert v-show="form.oaDictConfirmStatus != 'editing'"
                  style="margin-bottom: 15px;"
                  :title="form.latestTaskInfo"
                  type="info"
                  :closable="false"
                  effect="dark"
        >
        </el-alert>
        <el-form-item label="仓库" prop="fkStockUuid" v-show="false">
          <el-input v-model="form.fkStockUuid" />
        </el-form-item>
       <el-row>
         <el-col :span="12">
           <el-form-item label="单据编号" prop="docNum">
             <el-input v-model="form.docNum" placeholder="请输入单据编号" />
           </el-form-item>
           <el-form-item label="仓库" prop="fkStockUuid">
             <el-input v-model="form.fkStockUuid" v-show="false"/>
             <el-input placeholder="请点击右侧按钮选择仓库" readOnly="true" v-model="form.selectedStock" class="input-with-select"
                       :style="{width: '100%'}">
               <el-button type="info" plain
                          @click="dialog_show_stock"
                          slot="append" icon="el-icon-search"
               ></el-button>
             </el-input>
           </el-form-item>
         </el-col>

         <el-col :span="12">
           <el-form-item label="订单时间" prop="docDt">
             <el-date-picker clearable
                             v-model="form.docDt"
                             type="datetime"
                             format="yyyy-MM-dd HH:mm:ss"
                             value-format="yyyy-MM-dd HH:mm:ss"
                             placeholder="选择单据时间" :style="{width: '100%'}"
             >
             </el-date-picker>
           </el-form-item>
           <el-form-item label="经办人" prop="fkAttentionUserId">
             <el-input v-model="form.fkAttentionUserId" v-show="false"/>
             <el-input placeholder="请选择经办人" v-model="form.attentionUserName" class="input-with-select">
               <el-button @click="showDialog_selectAttentionUser" :style="{width: '100%'}"
                          slot="append"
                          icon="el-icon-search"></el-button>
             </el-input>
           </el-form-item>
         </el-col>
       </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="docNote">
              <el-input v-model="form.docNote" autosize type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="center">盘点明细信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddWmsInventorySheetDetails" :disabled="disabled">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteWmsInventorySheetDetails" :disabled="disabled">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" icon="el-icon-edit" size="mini" @click="addInventory" :disabled="disabled">写入即时库存</el-button>
          </el-col>
        </el-row>
        <el-table :data="wmsInventorySheetDetailsList" :row-class-name="rowWmsInventorySheetDetailsIndex" @selection-change="handleWmsInventorySheetDetailsSelectionChange" ref="wmsInventorySheetDetails">
          <el-table-column type="selection" width="50" align="center" />

          <el-table-column label="序号" prop="orderNum">
            <template slot-scope="scope">
              <el-input v-model="scope.row.orderNum" placeholder="请输入序号" />
            </template>
          </el-table-column>


<!--          <el-table-column label="单据日期" prop="docDt" width="180px">-->
<!--            <template slot-scope="scope">-->
<!--              <el-input v-model="scope.row.docDt" placeholder="请输入单据时间" />-->
<!--            </template>-->
<!--          </el-table-column>-->

          <el-table-column label="物料名称" prop="itemName" width="240px" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fkItemUuid" v-show="false"/>
              <el-input placeholder="请选择物料名称" readOnly="true" v-model="scope.row.itemName"
                        class="input-with-select">
              </el-input>
            </template>
          </el-table-column>

          <el-table-column label="物料编码" prop="itemNum" width="180px">
            <template slot-scope="scope">
              <el-input v-model="scope.row.itemNum"/>
            </template>
          </el-table-column>

          <el-table-column label="仓位" prop="stockPosName" width="180px" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.fkStockPosUuid" v-show="false"/>
              <el-input placeholder="请选择物料名称" readOnly="true" v-model="scope.row.stockPosName"
                        class="input-with-select">
              </el-input>
            </template>
          </el-table-column>



          <el-table-column label="计量单位" prop="measuringUnit" width="100px" align="center">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.measuringUnit"
                placeholder="请选择"
              >
                <el-option
                  v-for="dict in orderUnitOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </template>
          </el-table-column>

          <el-table-column label="数量" prop="inventoryQty" >
            <template slot-scope="scope">
              <el-input v-model="scope.row.inventoryQty" placeholder="请输入数量" @input="inputChange(scope)"/>
            </template>
          </el-table-column>
          <el-table-column label="盘点数量" prop="actualSheetQty">
            <template slot-scope="scope">
              <el-input v-model="scope.row.actualSheetQty" placeholder="请输入实际数量" @input="inputChange(scope)"/>
            </template>
          </el-table-column>
          <el-table-column label="差异" prop="differentQty">
            <template slot-scope="scope">
              <el-input v-model="scope.row.differentQty" placeholder="请输入差异数量" />
            </template>
          </el-table-column>

          <el-table-column label="备注" prop="docNote">
            <template slot-scope="scope">
              <el-input v-model="scope.row.docNote" placeholder="请输入备注" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="form.oaDictConfirmStatus != 'editing'">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog v-dialogDrag v-dialogDragWidth :title="title_confirm" :visible.sync="open_confirm" width="800px" append-to-body>
      <el-form ref="form_confirm" :model="form_confirm" label-width="100px">
        <el-form-item label="主键" prop="inventorySheetUuid" v-show="false">
          <el-input v-model="form_confirm.inventorySheetUuid" />
        </el-form-item>
        <el-form-item label="仓库" prop="fkStockUuid" v-show="false">
          <el-input v-model="form_confirm.fkStockUuid" />
        </el-form-item>
        <el-col :span="12">

          <el-form-item label="审批结果" prop="oaDictConfirmStatusSubmit">
            <el-select v-model="form_confirm.oaDictConfirmStatusSubmit" placeholder="请选择审批结果">
              <el-option
                v-for="dict in dict.type.wms_yes_no_sheet"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="意见建议" prop="confirmNote">
            <el-input v-model="form_confirm.confirmNote"
                      placeholder="请输入意见建议"
                      type="textarea"
                      autosize
                      maxlength="50"
                      show-word-limit/>
          </el-form-item>
        </el-col>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmForm">确 定</el-button>
        <el-button @click="cancel_confirm">取 消</el-button>
      </div>
    </el-dialog>


    <select-stock ref="component_selectStock" @ok="selectStock_done" />
    <select-user ref="component_selectAttentionUser" @ok="selectAttentionUser_done"/>
    <confirm ref="component_confirm" @ok="confirm_done"/>

  </div>
</template>

<script>
import { listInventorySheet, getInventorySheet, delInventorySheet, addInventorySheet, updateInventorySheet,listWmsInventory,getInventorySheetByUuid,getInventorySheetLoss } from "@/api/wms/inventorySheet";
import{newDocNum} from "@/api/oa/docNum";
import { parseTime } from '@/utils/ruoyi'
import selectStock from "../../wms/stock/selectStock";
import selectUser from "../../comn/userGroup/selectUser";
import {  updateStock } from "@/api/wms/stock";
import { listInventory } from "@/api/wms/inventory";
import confirm from "../../oa/confirm";
import { addStockIn} from "@/api/wms/stockIn";
import { addStockOut } from "@/api/wms/stockOut";


export default {
  name: "InventorySheet",
  dicts:['sys_normal_disable','wms_yes_no_sheet','oa_dict_confirm_status'],
  components:{ selectStock,selectUser,confirm},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedWmsInventorySheetDetails: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      disabled:true,
      // 盘点管理表格数据
      inventorySheetList: [],
      confirmedList: [],
      orderUnitOptions: [],
      // 盘点明细表格数据
      wmsInventorySheetDetailsList: [],
      // 弹出层标题
      title: "",
      title_confirm: "",
      title_oaConfirm: "",
      // 是否显示弹出层
      open: false,
      open_confirm: false,
      open_oaConfirm: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fkStockUuid: null,
        differentRate: null,
        sysNormalDisable: null,
        docTitle: null,
        docNum: null,
        docDt: null,
        docNote: null,
        fkAttentionUserId: null,
        fkConfirmUserIdSubmit: null,
        confirmDtSubmit: null,
        oaDictConfirmStatusSubmit: null,
        confirmNoteSubmitSubmit: null,
        fkConfirmUserId: null,
        confirmDt: null,
        oaDictConfirmStatus: null,
        confirmNote: null,
      },
      // 表单参数
      form: {},
      form_confirm: {},
      form_oaConfirm: {},
      // 表单校验
      rules: {
        fkStockUuid: [
          { required: true, message: "仓库id不能为空", trigger: "blur" }
        ],
        differentRate: [
          { required: true, message: "差异率不能为空", trigger: "blur" }
        ],
        sysNormalDisable: [
          { required: true, message: "状态不能为空", trigger: "blur" }
        ],
        docNum: [
          { required: true, message: "单据编号不能为空", trigger: "blur" }
        ],
        docDt: [
          { required: true, message: "单据时间不能为空", trigger: "blur" }
        ],
        fkAttentionUserId: [
          { required: true, message: "经办人ID不能为空", trigger: "blur" }
        ],
        oaDictConfirmStatusSubmit: [
          { required: true, message: "提交审核状态不能为空", trigger: "blur" }
        ],
        oaDictConfirmStatus: [
          { required: true, message: "盘点审核状态不能为空", trigger: "blur" }
        ],
        createBy: [
          { required: true, message: "创建者不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    /**获取计量单位字典数据*/
    this.getDicts("wms_dict_measuring_unit").then(response => {
      this.orderUnitOptions = response.data;
    });
  },
  methods: {

    /** 打开对话框：审核 */
    showDialog_confirm(row) {
      this.confirmPassed=row
      let obj = {
        tableName: 'wms_inventory_sheet',
        uuidColumn: 'inventory_sheet_uuid',
        fkUuid: row.inventorySheetUuid,
        attentionUserNickName: row.nickName,
        msg: `请审核盘点申请, 入库单号：${row.docNum}`
      }
      this.$refs.component_confirm.showDialog_confirm(obj);

    },
    inputChange(scope){
      scope.row.differentQty = parseFloat(scope.row.actualSheetQty )- parseFloat(scope.row.inventoryQty)
    },
    /** 查询盘点管理列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams)
      listInventorySheet(this.queryParams).then(response => {
        this.inventorySheetList = response.rows;
        console.log(this.inventorySheetList)
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
   // 取消按钮
    cancel_oaConfirm() {
      this.open_oaConfirm = false;
    },
    // 取消按钮
    cancel_confirm() {
      this.open_confirm = false;
    },
    // 表单重置
    reset() {
      this.form = {
        inventorySheetUuid: null,
        fkStockUuid: null,
        selectedStock: null,
        differentRate: null,
        differentQty: null,
        inventoryQty: null,
        actualSheetQty: null,
        sysNormalDisable: null,
        docTitle: null,
        docNum: null,
        docDt: parseTime(Date.now(), '{y}-{m}-{d} {h}:{i}'),
        docNote: null,
        fkAttentionUserId: null,
        attentionUserName: null,
        fkConfirmUserIdSubmit: null,
        confirmDtSubmit: null,
        oaDictConfirmStatusSubmit: null,
        confirmNoteSubmitSubmit: null,
        fkConfirmUserId: null,
        confirmDt: null,
        oaDictConfirmStatus: null,
        confirmNote: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.wmsInventorySheetDetailsList = [];
      this.resetForm("form");
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.inventorySheetUuid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.disabled = true
      this.form.oaDictConfirmStatus = 'editing'
      newDocNum({preCode:'PAND-', len: 12}).then(response => {
        this.form.docNum = response.msg
      })
      this.open = true;
      this.title = "添加盘点管理";
    },

    /** 审核按钮操作 */
    handleConfirm(row) {
      const inventorySheetUuid = row.inventorySheetUuid || this.ids
      getInventorySheet(inventorySheetUuid).then(response => {
        this.form_confirm = response.data;
        this.form_confirm.oaDictConfirmStatusSubmit = 'agree';
        this.wmsInventorySheetDetailsList = response.data.wmsInventorySheetDetailsList;
        this.open_confirm = true;
        this.title_confirm = "审核盘点管理";
      });
    },

    /**审核提交按钮*/
    confirmForm() {
        updateInventorySheet(this.form_confirm).then(response => {
          this.open_confirm = false;
          this.getList();
        });
      if(this.form_confirm.oaDictConfirmStatusSubmit!='agree' ){
        this.disabled='false'
        updateStock({sysNormalDisable:"0",stockUuid:this.form_confirm.fkStockUuid}).then(response => {
        });
      }
    },



    /** 修改按钮操作 */
    handleUpdate(row) {
      if(row.oaDictConfirmStatusSubmit == 'agree'){
        this.disabled = false
      }else{
        this.disabled = true
      }
      this.reset();
      const inventorySheetUuid = row.inventorySheetUuid || this.ids
      getInventorySheet(inventorySheetUuid).then(response => {
        this.form = response.data;
        console.log(this.form)
        this.form.actualSheetQty = this.form.inventoryQty
        this.form.selectedStock = row.stockName
        this.form.attentionUserName = this.form.userNickNameAndId
        this.form.oaDictConfirmStatus =
          ('editing' == this.form.oaDictConfirmStatus || 'reject' == this.form.oaDictConfirmStatus)
            ? 'editing' : this.form.oaDictConfirmStatus


        if(row.oaDictConfirmStatus!='editing'||row.oaDictConfirmStatus!='reject'||this.oaDictConfirmStatus!='editing'||this.oaDictConfirmStatus!='reject'){
          this.form.latestTaskInfo='💡 该条记录审核状态为'+
            this.selectDictLabel(this.dict.type.oa_dict_confirm_status, row.oaDictConfirmStatus||this.oaDictConfirmStatus)+'状态'+','+'不能修改'
        }
        this.wmsInventorySheetDetailsList = response.data.wmsInventorySheetDetailsList;
        this.open = true;
        this.title = "修改盘点管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.wmsInventorySheetDetailsList = this.wmsInventorySheetDetailsList;
          if (this.form.inventorySheetUuid != null) {
            updateInventorySheet(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              updateStock({sysNormalDisable:"盘点中",stockUuid:this.form.fkStockUuid}).then(response => {
              });
              this.open = false;
              this.getList();
            });
          } else {
            addInventorySheet(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              console.log(this.form.stockUuid)
              updateStock({sysNormalDisable:"盘点中",stockUuid:this.form.stockUuid}).then(response => {
              });
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const inventorySheetUuids = row.inventorySheetUuid || this.ids;
      this.$modal.confirm('是否确认删除盘点管理编号为"' + inventorySheetUuids + '"的数据项？').then(function() {
        return delInventorySheet(inventorySheetUuids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 盘点明细序号 */
    rowWmsInventorySheetDetailsIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 盘点明细添加按钮操作 */
    handleAddWmsInventorySheetDetails() {
      let obj = {};
      obj.fkStockPosUuid = "";
      obj.orderNum = "1";
      obj.fkItemUuid = "";
      obj.wmsDictMeasuringUnit = "";
      obj.inventorySheetQty = "";
      obj.inventoryQty = "";
      obj.actualSheetQty = "";
      obj.differentQty = "";
      obj.sysNormalDisable = "";
      obj.docTitle = "";
      obj.docNum = "";
      obj.docDt = "";
      obj.docNote = "";
      obj.fkAttentionUserId = "";
      obj.fkConfirmUserIdSubmit = "";
      obj.confirmDtSubmit = "";
      obj.oaDictConfirmStatusSubmit = "";
      obj.confirmNoteSubmitSubmit = "";
      obj.fkConfirmUserId = "";
      obj.confirmDt = "";
      obj.oaDictConfirmStatus = "";
      obj.confirmNote = "";
      this.wmsInventorySheetDetailsList.push(obj);
    },
    /** 盘点明细删除按钮操作 */
    handleDeleteWmsInventorySheetDetails() {
      if (this.checkedWmsInventorySheetDetails.length == 0) {
        this.$modal.msgError("请先选择要删除的盘点明细数据");
      } else {
        const wmsInventorySheetDetailsList = this.wmsInventorySheetDetailsList;
        const checkedWmsInventorySheetDetails = this.checkedWmsInventorySheetDetails;
        this.wmsInventorySheetDetailsList = wmsInventorySheetDetailsList.filter(function(item) {
          return checkedWmsInventorySheetDetails.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleWmsInventorySheetDetailsSelectionChange(selection) {
      this.checkedWmsInventorySheetDetails = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wms/inventorySheet/export', {
        ...this.queryParams
      }, `wms_inventorySheet.xlsx`)
    },
    /** 显示对话框：选择仓库 */
    dialog_show_stock() {
      this.$refs.component_selectStock.dialog_show_stock();
    },

    /** 完成：选择仓库*/
    selectStock_done(stock) {
      console.log(stock)
      this.form.fkStockUuid = stock.stockUuid
      this.form.selectedStock = stock.stockName
      this.form.stockUuid = stock.stockUuid,
        console.log(this.form.stockUuid)
    },
    /** 选择经办人 */
    showDialog_selectAttentionUser() {
      this.$refs.component_selectAttentionUser.show();
    },
    /** 选择经办人 - 完成 */
    selectAttentionUser_done(user) {
      this.form.fkAttentionUserId = user.userId
      this.form.attentionUserName = user.nickName
    },
    addInventory(){
      console.log(this.form.fkStockUuid)
      listWmsInventory({fkStockUuid:this.form.fkStockUuid,edit:'editing',reject:'reject',wait:'waiting'}).then(response=>{
        console.log(response)
        this.confirmedList = response.rows;
        console.log( this.confirmedList )
        if(this.confirmedList.length>0){
          this.$modal.msgError("即时库存写入失败,存在未审核的单据");
        }else{
          listInventory({fkStockUuid:this.form.fkStockUuid}).then(response=>{
            console.log(response)
            console.log(response.rows.length)
            if(response.rows.length > 0){
              this.wmsInventorySheetDetailsList = response.rows;
            }else{
              this.$modal.msgError("该仓库暂无即时库存");
            }
          });
        }
      });

    },

    confirm_done() {
      this.getList()
      this.updStock()
      this.addInventorySheet()
    },
    updStock(){
      /* 修改仓库状态 */
        console.log(this.confirmPassed.fkStockUuid)
        updateStock({sysNormalDisable:0,stockUuid:this.confirmPassed.fkStockUuid}).then(response => {
          console.log(response)
          this.getList()
        });
    },

    addInventorySheet(){
      console.log(this.confirmPassed)
      getInventorySheetByUuid(this.confirmPassed.inventorySheetUuid).then(response => {
        console.log(response)
        this.form = response.data
        this.form.wmsStockInDetailsList=response.data.wmsInventorySheetDetailsList
        this.form.wmsDictStockInType = '8'
        this.form.docDt = ''
        this.form.oaDictConfirmStatus = 'editing'
        console.log(this.form.wmsStockInDetailsList)
        if(this.form.wmsStockInDetailsList.length>0) {
          addStockIn(this.form).then(response => {
          });
        }
      });



      console.log(this.confirmPassed)
      getInventorySheetLoss(this.confirmPassed.inventorySheetUuid).then(response => {
        console.log(response)
        this.form_loss = response.data
        this.form_loss.wmsStockOutDetailsList=response.data.wmsInventorySheetDetailsList
        this.form_loss.wmsDictStockOutType = '9'
        this.form_loss.docDt = ''
        this.form_loss.oaDictConfirmStatus = 'editing'
        console.log(this.form_loss.wmsStockOutDetailsList)
        if(this.form_loss.wmsStockOutDetailsList.length>0){
          addStockOut(this.form_loss).then(response => {
          });
        }
      });
    },






  }
};
</script>
